using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace net.notdot.Attercop {
    public interface IFileHandler {
        /// <summary>
        /// Returns the file this peer would like the specified peer to send it.
        /// </summary>
        /// <remarks>
        /// No action is expected for this event.
        /// </remarks>
        string GetDesiredFile(PeerConnection conn);

        /// <summary>
        /// Called whenever an incoming connection from another peer is established.
        /// </summary>
        /// <remarks>
        /// A connection is only considered 'established' when the peer has connected and sent a valid HelloMessage.
        /// No action is expected for this event.
        /// </remarks>
        void HandleIncomingConnection(PeerConnection conn);

        /// <summary>
        /// Called whenever an incoming connection from another peer disconnects.
        /// </summary>
        /// <remarks>
        /// No action is expected for this event.
        /// </remarks>
        void HandleIncomingDisconnection(PeerConnection conn);

        /// <summary>
        /// Called whenever a connection is established with another peer.
        /// </summary>
        /// <remarks>
        /// A connection is only considered 'established' when we have sent a HelloMessage to the other peer.
        /// The peer does not have to handle sending the SendMeMessages, this is handled by the ClientInstance.
        /// 
        /// No action is expected for this event.
        /// </remarks>
        void HandleOutgoingConnection(PeerConnection conn);

        /// <summary>
        /// Called whenever a connection to another peer disconnects.
        /// </summary>
        /// <remarks>
        /// No action is expected for this event.
        /// </remarks>
        void HandleOutgoingDisconnection(PeerConnection conn);

        /// <summary>
        /// Called whenever a queue notification is received from the other peer.
        /// </summary>
        /// <remarks>
        /// No action is expected for this event.
        /// </remarks>
        void HandleQueueNotification(PeerConnection conn, QueueNotificationMessage m);

        /// <summary>
        /// Called whenever a peer starts transmitting a file.
        /// </summary>
        /// <remarks>
        /// The handler is expected to start reading from the provided stream if it wants the file.
        /// Alternately, it can close the stream (and the connection to the client with it) if the file
        /// is not wanted.
        /// </remarks>
        /// <param name="c">The ClientInstance handling this connection</param>
        /// <param name="p">The peer that sent the message</param>
        /// <param name="m">The IncomingFileMessage that was sent by the other peer</param>
        /// <param name="s">A readable stream that the file will be sent over</param>
        void HandleIncomingFile(PeerConnection conn, IncomingFileMessage m, Stream s);

        /// <summary>
        /// Called when the other peer requests a file.
        /// </summary>
        /// <remarks>
        /// When another peer sends SendMeMessage, the peer is expected to respond with either an
        /// IncomingFileMessage or a QueueNotificationMessage. These can be sent by invoking SendMessage()
        /// on the ClientInstance.
        /// </remarks>
        void HandleFileRequest(PeerConnection conn, SendMeMessage m);
    }
}
